package Exception;

import java.util.Scanner;

public class Login {
    private String userName;
    private String userPassword;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public void LoginInfo(String userName, String userPassword)
        throws UserNameException, UserPasswordException {
        if(!this.userName.equals(userName)) {
            throw new UserNameException("用户名错误！");
        }
        if(!this.userPassword.equals(userPassword)) {
            throw new UserPasswordException("密码错误！");
        }
        System.out.println("登陆成功！！");
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入用户名：");
        String name = scan.next();
        System.out.print("请输入密码：");
        String password = scan.next();
        Login login = new Login();
        login.setUserName(name);
        login.setUserPassword(password);
        try {
            login.LoginInfo("Tina", "317");
        } catch(UserNameException e) {
            e.printStackTrace();
        } catch (UserPasswordException e) {
            e.printStackTrace();
        }

    }
}
